<template>
  <div id="main">
    <el-container>
      <el-header>
        <div id="yonghu">[{{ username }}]用户欢迎您</div>
        <div id="guanli">
          <el-button type="primary" round @click="jump">管理者界面</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="220px">
          <PersonAside></PersonAside>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import PersonAside from '@/views/PersonAside.vue'
export default {
  data () {
    return {
      username: ''
    }
  },
  components: {
    PersonAside
  },
  created () {
    this.index()
  },
  methods: {
    index () {
      const item = JSON.parse(sessionStorage.getItem('user'))
      console.log(item);
      this.username = item.username
    },
    jump () {
      const item = JSON.parse(sessionStorage.getItem('user'))
      // 判断是否是管理者，若是则跳转至 /Kucun页面
      const that = this
      this.$http({
        method: "POST",
        url: '/lk/lk/userSearch',
        data: {
          name: item.username
        }
      }).then(function (response) {
        if (response.data.status == 0) {
          that.$router.push('/Kucun')
        } else if (response.data.status == 1) {
          alert(response.data.message)
        }

      })
    }
  }
}
</script>

<style lang="less">
html,
body,
#main {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  .el-container {
    height: 100%;
    .el-header {
      border-bottom: 1px solid #fff;
      background-color: #545c64;
      color: #fff;
      #yonghu {
        float: left;
        height: 100%;
        width: 200px;
        text-align: left;
        line-height: 60px;
      }
      #guanli {
        height: 100%;
        width: 150px;
        text-align: center;
        line-height: 60px;
        float: right;
      }
    }
    .el-main {
      background-color: aqua;
    }
  }
}
</style>